package com.youhong.teethcare.plaque.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioGroup;

import com.youhong.teethcare.R;

/**
 * Created by Administrator on 2018/9/12.
 */

public class PlaqueChooseDialog extends Dialog {

    ImageView iv_close;
    Button btn_ok;
    RadioGroup rg;

    public void setCallback(PlaqueOnClickCallback callback) {
        this.callback = callback;
    }

    PlaqueOnClickCallback callback = null;

    public static final int TYPE_NORMAL = 0;
    public static final int TYPE_PLAQUE = 1;


    public PlaqueChooseDialog(@NonNull Context context, int themeResId, int type) {
        super(context, themeResId);
        setContentView(R.layout.dialog_plaquechoose);
        getViews(type);
    }

    private void getViews(int type) {
        iv_close = findViewById(R.id.dialog_iv_close);
        iv_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PlaqueChooseDialog.this.dismiss();
            }
        });
        btn_ok = findViewById(R.id.plaqueChoose_btn_ok);
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (callback != null) {
                    int type = rg.getCheckedRadioButtonId() == R.id.plaqueChoose_rb_healthy ? 0 : 1;
                    callback.onCallback(type);

                }
                PlaqueChooseDialog.this.dismiss();
            }
        });
        rg = findViewById(R.id.plaqueChoose_rg);
        if (type == 0)
            rg.check(R.id.plaqueChoose_rb_healthy);
        else
            rg.check(R.id.plaqueChoose_rb_plaque);


    }

    public interface PlaqueOnClickCallback {
        void onCallback(int type);
    }
}